#!/bin/sh
set -e

REDISPORT=26381
INSTALL_DIR="/Users/ankang/develop/redis-5.0.7"
DEMO_DIR="/Users/ankang/develop/redis-demo/masterslave"
EXEC="${INSTALL_DIR}/src/redis-sentinel"
CONF="${DEMO_DIR}/conf/redis-sentinel-${REDISPORT}.conf"

case "$1" in
    start)
        echo "Starting Redis sentinel..."
        $EXEC $CONF
        ;;
    stop)
        pid=`ps aux | grep redis-sentinel | grep ${REDISPORT} | head -n 1 | awk '{print $2}'`
        if [ -n "$pid" ]
        then
                echo "Stopping Redis sentinel[${pid}]..."
                kill ${pid}
        else
                echo "Redis sentinel stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
